#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uint freq;
uchar time,xhcc,xh,qian,bai,shi,ge;
uchar code table[]={
0xC0,0xf9,0xA4,0xB0,
0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,
0xC6,0xA1,0x86,0x8E};
sbit fmq=P3^6;
sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_3=P2^3;
void delay(uint z);
void shownum(uchar qian,uchar bai,uchar shi,uchar ge,uchar cyc,uchar time);
void main()
{
	while(1)
	{
		if(time>100)
		{
			time=0;
		}
		else
		{
			time++;
		}
		xhcc=100/time;
		for(xh=0;xh<10;xh++)
		{
			fmq=0;
			delay(time);
			fmq=1;
			delay(time);
		}
		freq=10000/(time*2);
		qian=freq/1000;
		bai=freq%1000/100;
		shi=freq%100/10;
		ge=freq%10;
		shownum(qian,bai,shi,ge,1,1);
	}
}
void delay (uint z)
{
	uint x,y;
	for(x=z;x>0;x--)
		for(y=11;y>0;y--);
}
void shownum(uchar qian,uchar bai,uchar shi,uchar ge,uchar cyc,uchar time)
{
uchar xh;
for(xh=0;xh<cyc;xh++)
		{
			//qbsg
			P0=table[qian];
			P2_0=0;
			delay(time);
			P2_0=1;
			P0=table[bai];
			P2_1=0;
			delay(time);
			P2_1=1;
			P0=table[shi];
			P2_2=0;
			delay(time);
			P2_2=1;
			P0=table[ge];
			P2_3=0;
			delay(time);
			P2_3=1;
		}
}